Vue.filter("filterTimes", function(val) {
    let y = new Date(val).getFullYear();
    let m = new Date(val).getMonth() + 1 >= 10 ? new Date(val).getMonth() + 1 : '0' + (new Date(val).getMonth() + 1);
    let d = new Date(val).getDate() >= 10 ? new Date(val).getDate() : '0' + new Date(val).getDate();
    return y + "-" + m + "-" + d;
})
Vue.filter("filterTimes1", function(val) {
    let y = new Date(val).getFullYear();
    let m = new Date(val).getMonth() + 1 >= 10 ? new Date(val).getMonth() + 1 : '0' + (new Date(val).getMonth() + 1);
    let d = new Date(val).getDate() >= 10 ? new Date(val).getDate() : '0' + new Date(val).getDate();
    let h = new Date(val).getHours() >= 10 ? new Date(val).getHours() : '0' + new Date(val).getHours();
    let ms = new Date(val).getMinutes() >= 10 ? new Date(val).getMinutes() : '0' + new Date(val).getMinutes();
    return y + "-" + m + "-" + d + " " + h + ":" + ms;
})
Vue.filter('filterTypes', function(val) {
    var type;
    var vals = Number(val);
    switch (vals) {
        case 1:
            type = '待确定'
            break;
        case 2:
            type = '已确认'
            break;
        case 3:
            type = '已开票'
            break;
        case 4:
            type = '已结算'
            break;
    }
    return type;
})
var app = new Vue({
    el: '#app',
    data: {
        platfrom: '',
        orderNum: '',
        times: '',
        page: 1,
        //getIp: 'http://192.168.0.180:8085/CARSERV',
        //getIp: 'http://carnt.carnettong.com:8088/CARSERV', //正式环境
        getIp: 'http://121.40.78.200:88/CARSERV',
        allPlat: '',
        billArr: [],
        pageMess: '',
        allMess: '',
        loading: true,
		value4:'',
        pickerOptions2: {
            shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
        },
    },
    created() {

        this.getPlatFrom();
        this.getMess();
    },
    methods: {
        funIndex(index) {
            return index + (this.page - 1) * 8 + 1;
        },
        //合作平台列表
        getPlatFrom() {
            this.$http.post(this.getIp + '/PlatformUser/getPuList.action', {}, {
                emulateJSON: true
            }).then(
                res => {
                    if (res.body.STATUC_CODE == 1) {
                        this.allPlat = res.body.PLATFORMUSERARR;
                        let obj = {};
                        obj.COMPNAME = '全部';
                        obj.ID = '3';
                        this.allPlat.unshift(obj);
                        this.loading = false;
                    }
                }, err => {
                    console.log(err);
                }
            );
        },
        //待结算列表
        getMess() {
            var obj = {};
            obj.LIKESTRING = this.orderNum;
            obj.STARTTIME = '';
            obj.ENDTIME = '';
            obj.COMPNAME = this.platfrom == '全部' ? '' : this.platfrom;
            obj.PAGENUMBER = this.page;
            obj.STATUS = 3;//已开票即待结算状态
            this.$http.post(this.getIp + '/PlatformBill/listBillOfWorkOrder.action', obj, {
                emulateJSON: true
            }).then(
                res => {
                    if (res.body.STATUC_CODE == 1) {
                        this.billArr = res.body.BILLARR;
                        this.pageMess = res.body.PAGER;
                        this.allMess = res.body;
                        setTimeout(() => this.loading = false, 0);
                    }
                }, err => {
                    console.log(err);
                }
            );
        },
        //切换分页
        handleCurrentChange(val) {
            $("input[type='checkbox']").attr('checked',false);
            /* 这个作用是完善点击叉叉和清除时再搜索的bug    ----start*/
            if(this.value4 == null) this.value4 = '';
            /* 这个作用是完善点击叉叉和清除时再搜索的bug    ----end*/
            var start = this.value4[0] ? this.formatTimes(this.value4[0]) : '';
            var end = this.value4[0] ? this.formatTimes(this.value4[1]) : '';
            this.currentPage = val;
            this.page = val;
            //待对账列表
            let obj = {};
            obj.STATUS = '';
            obj.LIKESTRING = this.orderNum;
            obj.STARTTIME = start;
            obj.ENDTIME = end;
            obj.COMPNAME = this.platfrom == '全部' ? '' : this.platfrom;
            obj.PAGENUMBER = this.page;
            this.$http.post(this.getIp + '/PlatformBill/listBillOfWorkOrder.action', obj, {emulateJSON: true}).then(
                    res => {
                        if (res.body.STATUC_CODE == 1) {
                            this.billArr = res.body.BILLARR;
                            this.pageMess = res.body.PAGER;
                            this.allMess = res.body;
                        }
                    }, err => console.log(err)
            );
        },
        search() {
            /* 这个作用是完善点击叉叉和清除时再搜索的bug    ----start*/
            if(this.value4 == null) this.value4 = '';
            /* 这个作用是完善点击叉叉和清除时再搜索的bug    ----end*/
			var start = this.value4[0] ? this.formatTimes(this.value4[0]) : '';
            var end = this.value4[1] ? this.formatTimes(this.value4[1]) : '';
            var obj = {};
            obj.STATUS = '';
            obj.LIKESTRING = this.orderNum;
            obj.STARTTIME = start;
            obj.ENDTIME = end;
            obj.COMPNAME = this.platfrom == '全部' ? '' : this.platfrom;
            obj.PAGENUMBER = this.page;
	        this.$http.post(this.getIp + '/PlatformBill/listBillOfWorkOrder.action',obj, {emulateJSON: true}).then(
	                res => {
                        console.log(res);
	                    if (res.body.STATUC_CODE == 1) {
                            this.billArr = res.body.BILLARR;
                            this.pageMess = res.body.PAGER;
                            this.allMess = res.body;
	                    }
	                }, err => console.log(err)
	        );
        },
        typeSearch(num) {
            var obj = {};
            obj.STATUS = num;
            obj.LIKESTRING = this.orderNum;
            obj.STARTTIME = new Date(this.times[0]).getTime();
            obj.ENDTIME = new Date(this.times[1]).getTime();
            obj.COMPNAME = this.platfrom == '全部' ? '' : this.platfrom;
            obj.PAGENUMBER = 1;
            this.getMess(obj);
        },
        handleSizeChange(val) {
            this.page = val;
        },
        handleCurrentChange(val) {
            this.page = val;
        },
        settleDetail(item) {
            location.href = './settleDetail.html?billId=' + item.BILLID;
        },
		//格式
        formatTimes(val) {
            var y = new Date(val).getFullYear();
            var m = new Date(val).getMonth() + 1 >= 10 ? new Date(val).getMonth() + 1 : '0' + (new Date(val).getMonth() + 1);
            var d = new Date(val).getDate() >= 10 ? new Date(val).getDate() : '0' + new Date(val).getDate();
            var h = new Date(val).getHours() >= 10 ? new Date(val).getHours() : '0' + new Date(val).getHours();
            var ms = new Date(val).getMinutes() >= 10 ? new Date(val).getMinutes() : '0' + new Date(val).getMinutes();
            return y + "-" + m + "-" + d + " " + h + ":" + ms;
        },
        //导出
        excel() {
            /* 这个作用是完善点击叉叉和清除时再搜索的bug    ----start*/
            if(this.value4 == null) this.value4 = '';
            /* 这个作用是完善点击叉叉和清除时再搜索的bug    ----end*/
			var start = this.value4[0] ? this.formatTimes(this.value4[0]) : '';
            var end = this.value4[0] ? this.formatTimes(this.value4[1]) : '';
            let str1 = 'STATUS=';
            let str2 = 'LIKESTRING=' + this.orderNum;
            let str3 = 'STARTTIME=' + start;
            let str4 = 'ENDTIME=' + end;
            let str5 = 'COMPNAME=' + this.platfrom;
            let str6 = 'PAGENUMBER=1';
            let url = this.getIp + '/PlatformBill/listBillOfWorkOrderExcel.action?' + str1 + '&' + str2 + '&' + str3 + '&' + str4 + '&' + str5;
            window.open(url);
        },
    },
    components: {}
})
